layui.use(['form', 'layer', 'laydate', 'table', 'laytpl'], function () {
var form = layui.form,
layer = parent.layer === undefined ? layui.layer : top.layer,
$ = layui.jquery,
laytpl = layui.laytpl,
laydate = layui.laydate,
table = layui.table;

table.render({
    elem: '#demo'
    ,toolbar: '#toolbarDemo'
    ,height: 'full-200'
    ,url: '/${gvo.headSmallEntityName}/get${gvo.entityName}List.htm' //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
        {type: 'checkbox', fixed: 'left'}
    <#list gvo.propertyVoList as p>
        <#if p.propertyName == "id">
        ,{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
        <#else>
        ,{field: '${p.propertyName}', title: '${p.webPropertyName}', width:${p.webPropertyLength}}
        </#if>
    </#list>
        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:270}
    ]]
});

//搜索【此功能需要后台配合，所以暂时没有动态效果演示】
$(".search_btn").on("click", function () {
    table.reload("tableInfo", {
        height: 'full-100',
        page: {
            curr: 1 //重新从第 1 页开始
        },
        where: {
            name: $(".name").val(),  //搜索的关键字
            phone: $(".phone").val(),  //搜索的关键字
            account: $(".account").val()  //搜索的关键字
        }
    })
});

//添加
$(".add_users_btn").click(function () {

})


function deleteById(edit) {
    //alert(edit.id)
    $.ajax({
        url: ctx + '/${gvo.headSmallEntityName}/electricFence/delete.htm',
        dataType: "json",
        type: "POST",
        data: {
            id: edit.id  //id
            //vehicleInfoId: edit.vehicleInfoId //车辆id
        },
        success: function (res) {
            if (res == "1") {
                top.layer.msg("删除成功");
            } else {
                return top.layer.msg("删除失败！");
            }
            layui.layer.closeAll();
            table.reload('tableInfo');
        },
        error: function (res) {
        }
    });
}

function openWin(edit ,url) {
    var index = layui.layer.open({
        title: edit == '' ? '新增区域' : "设置规则",
        type: 2,
        //skin: 'layui-layer-rim', //加上边框
        //area: ['95%', '90%'], //宽高
        content: url,
        success: function (layero, index) {
        var body = layui.layer.getChildFrame('body', index);
        setTimeout(function () {
        layui.layer.tips("点击返回", '.layui-layer-setwin .layui-layer-close', {
            tips: 3
            });
            }, 500)
        }
    })
    layui.layer.full(index);
    //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
    $(window).on("resize", function () {
        layui.layer.full(index);
    })
}


});